import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/21 9:44
 * @description 优先队列
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int[][] kClosest(int[][] points, int k) {
        PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> {
            return b[0]*b[0] + b[1]*b[1] - (a[0] * a[0] + a[1] * a[1]);
        });
        for (int[] p : points) {
            if (pq.size() <= k) {
                pq.add(new int[]{p[0], p[1]});
            }else {
                int[] top = pq.peek();
                int x = p[0], y = p[1], x1 = top[0], y1 = top[1];
                if (x * x + y * y < x1 * x1 + y1 * y1) {
                    pq.poll();
                    pq.add(p);
                }
            }
        }
        return pq.toArray(new int[][]{});
    }
}
